<?php if ( $_SESSION['logged_in'] == FALSE ) redirect (base_url ()); ?>
<script language="javascript" type="text/javascript">
<!-- 
//$(function() {
function loadtabs() {
            var theme = getDemoTheme();

            // Create jqxTabs.
        //    $('#jqxTabs').jqxTabs({ width: '100%', height: 300, position: 'top', theme: theme });
            $('#settings div').css('margin-top', '10px');
            // $('#jqxTabs').jqxTabs({ selectionTracker: true });
            $('#jqxTabs').jqxTabs({ width: '100%', height: 250, animationType: 'fade', selectionTracker: true });
};
        
        

function checkaddress(){
        // checks to see is the house number and roadname are registered in this area
	var ajaxRequest;  

	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	   } catch (e){
		// Internet Explorer Browsers
		try {
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
        
        // this function that will receive data sent from the server
        ajaxRequest.onreadystatechange = function(){
            if(ajaxRequest.readyState == 4){ 
		if(ajaxRequest.status == 200) {
                    var property = ajaxRequest.responseText;
                    // document.getElementById("adda").disabled = true;  to be sotred
                    // alert(property);
                    document.getElementById("property").innerHTML = property;
                } else {
                    document.getElementById("property").innerHTML = "An error has occurred: "+ajaxRequest.statusText;
                }
           }
      }
        
        var pnum = document.regmod.roadnum.value;
        var streetsel = document.regmod.roadname;
        var road = streetsel[streetsel.selectedIndex].value;
        var roadname = streetsel[streetsel.selectedIndex].text;
        document.getElementById("property").innerHTML = "Checking for property info "+pnum+" roadname : "+roadname;
         
        // Send the Request to the server
        url = "/index.php/AJAXgetaddress?pnum="+pnum+"&street="+roadname+"&aid="+aid;
        ajaxRequest.open("GET", url  , true);
        ajaxRequest.send();
}

function addproperty(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
        
        // Create a function that will receive data sent from the server
        ajaxRequest.onreadystatechange = function(){
            if(ajaxRequest.readyState == 4){ 
		// (Complete) Get the data from the server's response
              //  document.prereg.email.value = ajaxRequest.responseText;
                var addp = ajaxRequest.responseText;
               // alert(property);
               // document.getElementById("info").innerHTML = addp;
            }
        }
        
        var pnum = document.regmod.propnum.value;
        var streetsel = document.regmod.roadname;
        var road = streetsel[streetsel.selectedIndex].value;
        var roadname = streetsel[streetsel.selectedIndex].text;
        
       //   var roadname = document.regmod.roadname.valueOf() ;
        document.getElementById("property").innerHTML = "Adding property "+pnum+" roadname : "+roadname+" Street ID "+road+" Area : "+areaname+" Aid : "+aid;
    
     
     // Send the Request to the server
     if (pnum == 0) { 
         alert("Property number can not be 0"); 
     } else {
        ajaxRequest.open("GET", "/index.php/AJAXAddAddress?pnum="+pnum+"&street="+roadname+"&aid="+aid+"&areaname="+areaname  , true);
        ajaxRequest.send(); 
     }
}




function getcomments() {
  //  var ajaxRequest;  // The variable that makes Ajax possible!
    
    var GetReqComments;
	try{ // Opera 8.0+, Firefox, Safari
		GetReqComments = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			GetReqComments = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				GetReqComments = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
        
        // function that will receive data sent from the server
        GetReqComments.onreadystatechange = function(){
            if(GetReqComments.readyState == 4){ 
	      var cres = GetReqComments.responseText;
              //alert(cres);
              document.getElementById("comments").innerHTML = cres;
            } 
        }
        
        var url = "/index.php/AJAXGetComments?rid="+rid ;
       // alert(url);
        GetReqComments.open("GET", url , true);
        GetReqComments.send();    
}


function addcomment() {
  // Adds a comment to the registration
    var addcom;
    
	try{ // Opera 8.0+, Firefox, Safari
		addcom = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			addcom = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
			    addcom = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
     if (addcom)  { 
        
        var c = document.getElementById("newcomment").value;
        var url = "/index.php/AJAXAddcomment?rid="+rid+"&com="+c ;
         
        // document.getElementById("comments").innerHTML = "Adding Comment "+c;
        
        addcom.open("GET", url , false);
        
        addcom.send(null); 
        
        
        // function that will receive data sent from the server
        addcom.onreadystatechange = function() {
          //  alert("We are here  :"+addcom.readyState);
            if(addcom.readyState == 4 && addcom.status == 200) { 
	      var cres = addcom.responseText;
           //   alert(cres);
           //   document.getElementById("comments").innerHTML = cres;
           //   if (cres.length > 0) { alert(cres); }
           //   confirm('Reload comments');
              getcomments();  
            } else {
                document.getElementById("occupants").innerHTML = "State : "+addcom.readyState+"  Status : "+addcom.status;
            }
        }
   }
}

function addrverified() {
// locks the changing of the address field
    if (document.getElementById("addressverified").checked ) {
        document.getElementById("adda").disabled = true;
      //  document.regmod.roadname.disabled = true ;
        document.getElementById("roadnum").setAttribute('readonly', 'readonly') ;
    } else {
        document.getElementById("roadnum").removeAttribute("readonly");
        
   //     document.getElementById("occupants").innerHTML = "Address not Verified";
    //    document.regmod.roadname.disabled = false ;
    }
}

function rolechange() {
// depending on the role selected -- some roles do not have an address 
    var rolesel = document.regmod.role;
    var role = rolesel[rolesel.selectedIndex].value;
  //  var roletxt = rolesel[rolesel.selectedIndex].text;
    
    if (role === 'react' || role === 'advert' || role === 'spvdr' || role === 'public') {
     //   document.regmod.roadname.disabled = true ;
        document.getElementById("roadnum").value = 'NotAppl';
        document.getElementById("roadnum").setAttribute('readonly', 'readonly') ;
        document.getElementById("addressverified").setAttribute('readonly', 'readonly');
        document.getElementById('pinfo').setAttribute('hidden', 'hidden') ;
        document.getElementById('addp').setAttribute('hidden', 'hidden') ;
        
    } else {
      //  alert("Role : "+role+" / "+roletxt);
        document.getElementById("roadnum").removeAttribute("readonly");
        document.getElementById("addressverified").removeAttribute("readonly");
        document.getElementById('pinfo').removeAttribute("hidden");
        document.getElementById('addp').removeAttribute("hidden");
      //  document.regmod.roadname.disabled = false ;
    }
    
}

function streetupdate() {
// becuse the dropdown for street could be disabled therfore no post data
// the value when it is not disabled is coppied to a hidden input 'street' onchange()
    var stt = document.regmod.roadname;
    document.getElementsByName("street").value = stt[stt.selectedIndex].value;
    document.getElementsByName("street").innerHTML = stt[stt.selectedIndex].value;
}

function frmsubmit(){
    alert(document.getElementsByName("street").value);
}



//-->
</script> 
<?php

/*
 * This form manages the registration after a user has validated their email address 
 * 
 */
if ( $_SESSION['logged_in'] == FALSE ) redirect (base_url ());
?>
<div class="multitab d1">

<?php     
/* Declare vars for Javascript */
$areaname = $regd['areas']['areaname'];
$aid = $regd['areas']['aid'];
?>
<script language="javascript" type="text/javascript">
    var areaname = "<?php echo $areaname; ?>";
    var aid = "<?php echo $aid; ?>";
    var rid = "<?php echo $rid; ?>";
    var canaddprop = false;
</script>    

<?php

$hidden = array('id' => $rid );
//var_dump($_SESSION['userdata']['filt']);
echo '<a href="'.$baseurl.'index.php/listRegistration/'.$_SESSION['userdata']['filt'].'">
         <img class="btnimg" src="'.$baseurl.'public/images/close.png" align="right" alt="close" title="Close" border="0" />
      </a>';
if ($status) {
    $options = array('name' => 'regmod', 'id' => 'regmod');    
    echo form_open($baseurl.'index.php/manregbyemail', $options ,$hidden);
    echo form_fieldset('<h2> Moderate Registration </h2>');
?>
<table>
    <tr>
        <td width="100px" >
            <?php   echo form_label('Name *', 'Name'); 
                $namec = array('name' => 'Name', 
               'id' => 'Name',  
               'maxlength'   => '100',
               'value'       => $regd['Name'],
               'style'       => 'width: 200px' ); ?>  </td>
        <td width="230px" ><?php echo form_input($namec); ?>       </td>
        <td width="100px" ><?php echo form_label('RID'); ?></td>
        <td width="230px" ><?php echo $regd['id']; ?></td>
        <td width="180px" ><?php 
            echo form_error('Name'); 
            echo form_error('mobile'); 
            echo form_error('roadnum'); 
            echo form_error('street');  
          //  echo form_hidden('street', $regd[0]['street']);
     ?></td>
    </tr>
    <tr>
        <td> <?php echo form_label('Email *', 'username'); 
            $usernamec = array('name' => 'username', 
            'id' => 'username',  
            'maxlength'   => '100',
            'readonly'    => true, 
            'value'       => $regd['username'],
            'style'       => 'width: 200px' ); ?> </td> 
        <td> <?php echo form_input($usernamec); ?> </td>
        <td> <?php echo form_label('Date on System', '');  ?> </td>
        <td> <?php echo date('d M Y H:i:s', $regd['datesumbit']->sec); ?> </td>
        
    </tr>
    <tr>
        <td> <?php echo form_label('Mobile *', 'mobile'); $mobilec = array('name' => 'mobile', 
               'id' => 'mobile',  
               'maxlength'   => '10',
              'value'       => $regd['mobile'],
              'style'       => 'width: 100px' ); ?> </td>
        <td> <?php echo form_input($mobilec); ?> </td>
        <td> <?php echo form_label('Type', 'regtypetype'); $regtypetypec = array('name' => 'regtypetype', 
               'id' => 'regtypetype',  
               'maxlength'   => '10',
               'readonly'    => true,
              'value'       => $regd['regtypetype'],
              'style'       => 'width: 300px' ); ?> </td>
        <td> <?php echo form_input($regtypetypec); ?> </td>
        
    </tr>
    <tr>
        <td> <?php echo form_label('House Number *', 'roadnum'); $raodnumc = array('name' => 'roadnum', 'id' => 'roadnum',  
              'maxlength'   => '20',
              'value'       => $regd['roadnum'],
             
              'style'       => 'width: 50px' ); 
        echo '<br />';
        echo form_label('Street *', 'roadname');?> </td>
        
        <td> 
            <?php 
            echo '<span>'.form_input($raodnumc).'</span>';
            echo '<span><a id="addi" href="#" onclick="checkaddress()"><img class="btnimg" src="'.$baseurl.'public/images/info.png"  alt="Address Info" title="Address Info" /></a></span>';
            echo '<span><a id="adda" href="#" onclick="addproperty()"><img class="btnimg" src="'.$baseurl.'public/images/add.png"  alt="Add the Address" title="Add the Address" /></a></span><br />';
          //  echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<acall id="pinfo" onclick="checkaddress()">Information</acall>';
          //  echo '&nbsp;&nbsp;<acall id="addp" onclick="addproperty()">Add Property</acall>'; echo '<br>'.form_error('propnum'); 
            /* now get the streets */
            $options = [];
            //var_dump($streets);
            
            if (!$streets == FALSE) {
            $options = array_merge($options, array('null' => 'Not Applicable'));
            foreach($streets as $value)
              {
                $mid = $value['id'] ;
                $t = array($mid => $value['Street']);
                $options = array_merge($options, $t); 
              }
            } else {$options = array_merge($options, array('null' => 'No Streets defined')); }
            $js = 'onchange="streetupdate()"';
            echo form_dropdown('roadname', $options, $regd['street'], $js); ?>
       </td>
       <td colspan="2" id="checks" >
            <span>Address Verified</span>
            <span>&nbsp;&nbsp;&nbsp;&nbsp;
                <?php 
                $cb = array('name' => 'addressverified',
                 'id' => 'addressverified',
                 'value' => TRUE,  
                 'style' => 'margin:10px'  );
                $js = 'onchange="checkaddress(); addrverified();"';
                echo form_checkbox($cb,'', $regd['addressverified'], $js); 
                ?>
            </span><br />
            <span>Request Status</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <span><?php
                  // $options = 'name="status" id="status" style="width: 200px"' ;
                  $data = array('open' => 'Open waiting Moderation',
                   'evaled' => 'Email validtated - moderation',
                   'modp' => 'Moderation in progress',
                   'feedb' => 'Waiting Feedback',
                   'accept' => 'Registration Accepted',
                   'reject' => 'Registration Rejected',
                   'cancel' => 'Registration cancelled');
                   $current = $regd['status'];
                   
                   echo form_dropdown('status', $data, $current); 
                  ?>
            </span>
            
        </td>
   </tr>
   <tr>
        <td> <?php echo form_label('Role', 'role'); $level = array('name' => 'role', 'id' => 'role' ); 
        $options = [];
        foreach($roles as $value)
        {
            $t = array($value['_id'] => $value['Display']);
            $options = array_merge($options, $t); 
        }
        $js = 'onchange="rolechange()"'
       // $selected = $regd[0]['role'];
        //print_r($options);
        ?> </td>
        <td> <?php echo form_dropdown('role', $options,$regd['role'], $js); ?> </td>
        <td colspan="2" rowspan="2" id="saddr" >
            <?php 
            echo 'Address and Motivation<br />'; 
            $level = array('name' => 'oaddrr', 'id' => 'oaddrr', 
                'value' => $regd['address'].chr(13).'-------------------------------'.chr(13).'Motivation : '.chr(13).$regd['motivation'], 
                'readonly' => true, 'cols' => 50, 'rows' => 3 );
            $options = array(); 
            echo form_textarea($level);  
            ?> 
        </td>
    </tr>
    <tr>
        <td> <?php echo form_label('Area', 'areas');  
        $selected = $areaname;
        echo "</td>" ;
        $areasc = array('name' => 'areas', 
            'id' => 'areas',  
            'maxlength'   => '100',
            'readonly'    => true, 
            'value'       => $selected,
            'style'       => 'width: 200px' ); ?>  
        <td> <?php echo form_input($areasc);  ?> </td>
   </tr>
   <tr>
        <td colspan="4" align="right" > 
            <?php 
            echo '<input type="submit" name="save" value="Save" onclick="frmsubmit()" />';
        //    echo form_submit('save', 'Save');
            echo form_reset('reset', 'Reset');
            ?>  
   </tr>
</table>    
<?php
form_fieldset_close();
form_close();
} else {
    /*
     * Email has not been validated therefore $status = False so we canot moderate 
     */
    echo '<h2> Can <strong>NOT</strong> moderate because the user has not yet validated their email address </h2> ';  
    echo "<p> Please contact ".$regd['Name']." on either their mobile ".$regd['mobile']." or via email 
       on ".$regd['username']." and request they confirm thier email address so that you can proceed</p>" ;
}
?>
<!--</div> content-->
</div> <!--Multitab-->
<!-- Load and Manage Comments -->
<!--<div class="tabs">
     <span id="comtab" >Comments</span> <span id="proptab">Property</span> <span id="occtab">Occupants</span> <span id="Inctab">Incidents</span>
</div>-->

<!--<div class="comments" name="comments" id="comments" >.</div>-->
<div id='jqxWidget2'>
        <div id='jqxTabs'>
            <ul>
                <li style="margin-left: 30px;">Comments</li>
                <li>Property Details</li>
                <li>Occupants</li>
<!--                <li>Incidents</li>
                <li>Documents</li>-->
            </ul>
            
            <div id="comments">
             <div id='tabmenubar'>
                 <a href="#addcomm">
                     <img src="<?php echo $baseurl; ?>public/images/add.png"  alt="Add Comment" title="Add Comment" />
                 </a>
             </div>
              
            </div>
            <div id="property">
                Here we will list property Details
            </div>
            <div id="occupants">
                List of occupants on the property
            </div>
<!--            <div id="incidents">
                List of recent incidents
            </div>
            <div id="documents">
                Listing of any relevant documents
            </div>       -->
        </div>     
</div>
<!-- Load and Property Information -->

<div id="addcomm" class="modalDialog">
	<div>
		<a href="#close" title="Close" class="close">X</a>
		<h2>Add a comment</h2>
                <textarea name="newcomment" id="newcomment" cols="50" rows="5"></textarea><br />
                <input type="submit" value="Save" onclick="addcomment() ; javascript:parent.closeIFrame();">
<!--                 javascript:parent.closeIFrame();-->
	</div>
        <a href="javascript:parent.closeIFrame();">close</a>
</div>

<div id="showprop" class="modalDialog">
	<div>
		<a href="#close" title="Close" class="close">X</a>
		<h2>Property Info</h2>
	</div>    
        <a href="javascript:parent.closeIFrame();">close</a>
</div>

<script language="javascript" type="text/javascript"> loadtabs(); getcomments(); </script>

<!--  <a href='#addcomm'>Add comment</a> <a href='#' onclick='getcomments();'>Refresh</a> -->